#ifndef VIDEODISCOVERYTHREAD_H
#define VIDEODISCOVERYTHREAD_H

#include <QObject>
#include <QThread>
#include <QWaitCondition>
#include <QMutex>
#include <QMultiMap>
#include <gst/pbutils/pbutils.h>
#include "videoplayer.h"

/*
    视频探测器
*/
class VideoDiscover : public QThread
{
    Q_OBJECT
public:
    explicit VideoDiscover(QObject *parent = nullptr);
    ~VideoDiscover();

    void addMedia(const MediaInfo& media);
    void removeMedia(const QString& mediaId);
    bool containId(const QString& mediaId);
    bool containUrl(const QString& mediaUrl);

    void startDiscover();
    void stopDiscover(bool wait=false);

    int timeout();
    void setTimeout(int msec);
    int interval();
    void setInterval(int msec);

signals:
    void playable(const MediaInfo& media);

protected:
    void run() override;

private:
    bool m_stopReq;
    int m_timeout;
    int m_interval;
    QMutex m_resumeMutex;
    QWaitCondition m_resumeCond;
    QMutex m_newMediaMutex;
    QWaitCondition m_newMediaCond;

    QMutex m_mediasMutex;
    QVector<MediaInfo> m_medias;
};

#endif // VIDEODISCOVERYTHREAD_H
